package com.zyzy.leftfourdead.adapter.ProductActivityAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zyzy.leftfourdead.R;
import com.zyzy.leftfourdead.helper.BaseAdapterHelper;
import com.zyzy.leftfourdead.helper.MyListView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hqd on 2016/8/24.
 */
public class ProductListViewListAdapter extends BaseAdapter {

    public Context context = null;
    public  List<Map<String, String>> list = null;
    public LayoutInflater inflater = null;

    public ProductListViewListAdapter(Context context,List<Map<String, String>> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_product_listview_list, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (list.get(position).get("brand")!=null){
            viewHolder.textView_item_product_listview_lift.setText("品牌");
            viewHolder.textView_item_product_listview_right.setText(list.get(position).get("brand"));
        }
        if (list.get(position).get("weight")!=null){
            viewHolder.textView_item_product_listview_lift.setText("重量");
            viewHolder.textView_item_product_listview_right.setText(list.get(position).get("weight"));
        }
        if (list.get(position).get("pack")!=null){
            viewHolder.textView_item_product_listview_lift.setText("包装");
            viewHolder.textView_item_product_listview_right.setText(list.get(position).get("pack"));
        }
        if (list.get(position).get("storage_time")!=null){
            viewHolder.textView_item_product_listview_lift.setText("保质期");
            viewHolder.textView_item_product_listview_right.setText(list.get(position).get("storage_time"));
        }
        if (list.get(position).get("storage_method")!=null){
            viewHolder.textView_item_product_listview_lift.setText("贮藏方法");
            viewHolder.textView_item_product_listview_right.setText(list.get(position).get("storage_method"));
        }
        return convertView;
    }

    class ViewHolder {
        private TextView textView_item_product_listview_lift;
        private TextView textView_item_product_listview_right;

        public ViewHolder(View convertView) {
            textView_item_product_listview_lift = (TextView) convertView.findViewById(R.id.textView_item_product_listview_lift);
            textView_item_product_listview_right = (TextView) convertView.findViewById(R.id.textView_item_product_listview_right);
        }
    }

    //    刷新list
    public void reloadListView(List<Map<String,String>> data, boolean isClear) {
        if (isClear) {
            list.clear();
        }
        list.addAll(data);
        notifyDataSetChanged();
    }
}
